function edf2asc2eye(folder)


if nargin<1,
    folder = uigetdir([],'locate a folder with *.edf files in it.');
end
cd(folder)
if nargin<2,
    eye_used = 0 ;
end
if eye_used ~= 2,
    commandstr = 'EDF2ASC %s.edf %s.asc -l -miss 9999 -sg -s'; % left eye
else
    commandstr = 'EDF2ASC %s.edf %s.asc -r -miss 9999 -sg -s' ;% right eye
end

edffiles=dir('*.edf');edffiles={edffiles.name}';
for i =1:length(edffiles)
        filename=[edffiles{i}(1:end-3) 'asc'];
    if exist(filename,'file')==2
        delete(filename)
    end
    [s, w] = dos(sprintf(commandstr,edffiles{i}(1:end-4),edffiles{i}(1:end-4))) ;
    [t,x,y,a,c] =textread(filename,'%s %s %s %s %s'); disp(['file: ' filename ' loaded'])
    clear c;
    t(strcmp(t, '.') )={'0.0'}; t=str2num(char(t ));disp('str2num(t )')
    x(strcmp(x, '.') )={'0.0'}; x=str2num(char(x ));disp('str2num(x )')
    y(strcmp(y, '.') )={'0.0'}; y=str2num(char(y ));disp('str2num(y )')
    a(strcmp(a, '.') )={'0.0'}; a=str2num(char(a ));disp('str2num(a )')
    if t(end)==0
        t(end)=[];
        x(end)=[];
        y(end)=[];
        a(end)=[];
    end
    delete(filename)
    %figure(i);clf; hold on
    %plot(t,x,'b')
    %plot(t,y,'r')
    %plot(t,a,'k')
    figure(10+i);clf; hold on
    x(x==9999)=NaN;
    y(y==9999)=NaN;
    a(a==9999)=NaN;
    plot(t,x,'b')
    plot(t,y,'r')
    plot(t,a,'k')
    save([edffiles{i}(1:end-4) 'eye.mat'],'t','x','y','a')
    close all
end

